<template>
    <div class='order'>
        <div class="container">
            <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="search-con">
                <el-col :span="24">
                    <el-form-item>
                        <el-button size="mini" v-for="item, index in btnList" :key="index" @click="changeTab(item, index)"
                            :type="curLine == index ? 'primary' : 'default'">
                            {{ item.dictLabel }}</el-button>
                    </el-form-item>
                </el-col>
                <el-form-item label="输入搜索：" prop="key_order_no" style="margin-right:25px;">
                    <el-input v-model="queryParams.key_order_no" placeholder="订单编号" clearable size="small" />
                </el-form-item>
                <el-form-item label="收货人：" prop="key_name" style="margin-right:25px;">
                    <el-input v-model="queryParams.key_name" placeholder="用户名/收货人姓名/手机号码" clearable size="small" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
                        v-hasPermi="['customer:manage:export']">导出
                    </el-button>
                </el-form-item>
            </el-form> -->
            <el-row :gutter="10" class="mb8">
                <!-- <el-col :span="22">
                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="title='新增';handleShow='add'" v-hasPermi="['user:depart:add']">
                        新增</el-button>
                </el-col> -->
                <!-- <el-col :span="22">
                    <el-button type="primary" icon="el-icon-edit" size="mini" @click="handleBulk"
                        v-hasPermi="['customer:manage:add']">
                        批量修改</el-button>
                </el-col> -->
                <el-col :span="1.5"><span style="font-size:110%;font-weight: bold;color:#30B08F;">共{{ listCount }}个</span></el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table border v-loading="loading" :data="tableList" ref="tableList" v-tableHeight
                :height="tableList.length > 0 ? '900px' : '120px'" @selection-change="handleSelectionChange"
                @row-click="toggleSelection">
                <!-- <el-table-column type="selection" width="55" align="center" /> -->
                <el-table-column label="订单编号" align="center" prop="order_no" />
                <el-table-column label="创建时间" align="center" prop="create_time" />
                <el-table-column label="快递公司" align="center" prop="company_name" />
                <el-table-column label="快递单号" align="center" prop="send_number" />
                <el-table-column label="收货人" align="center" prop="address_name" />
                <el-table-column label="收货电话" align="center" prop="address_mobile" />
                <el-table-column label="收货地址" align="center" prop="total_price" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.address_province}}{{ scope.row.address_city }}</span>
                        <span>{{ scope.row.address_area}}{{ scope.row.address_detailed }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="收货备注" align="center" prop="send_remark" />
                <el-table-column label="收货状态" align="center" prop="orders_state">
                    <template slot-scope="scope">
                        <span>
                            {{ selectDictLabel(receiveStatus, scope.row.is_take) }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-document"
                        @click.stop="handleGoods(scope.row)"
                            v-hasPermi="['user:depart:edit']">
                            收货商品
                        </el-button>
                        <!-- 
                        <el-button v-if="scope.row.orders_state == 0" icon="el-icon-circle-close" size="mini" type="text"
                            @click="handleDelete(scope.row)" v-hasPermi="['user:depart:start']">取消订单
                        </el-button>
                        <el-button v-if="scope.row.orders_state == 2"
                            @click="orderNo = String(scope.row.order_no); handleShow = 'tracking'" size="mini" type="text"
                            v-hasPermi="['user:depart:stop']">物流跟踪
                        </el-button>
                        <el-button v-if="scope.row.orders_state == 1 || scope.row.orders_state == 2"
                            @click="orderNo = String(scope.row.order_no); handleShow = 'delivery'" size="mini" type="text"
                            v-hasPermi="['user:depart:stop']">发货设置
                        </el-button> v-if="scope.row.orders_state == 0" @click="orderNo = String(scope.row.order_no); handleShow = 'confirm'"-->
                        <el-button v-if="scope.row.is_take == 0" @click="handleConfirm(scope.row)" size="mini" type="text"
                            v-hasPermi="['user:depart:stop']">确认收货
                        </el-button>
                        <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                            v-hasPermi="['user:depart:del']">
                            删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="pageCount > 0" :pageCount="pageCount" :page.sync="queryParams.page"
                :limit.sync="queryParams.limit" @pagination="getList" />
        </div>
        <el-dialog title="商品信息" visible v-if="handleShow == 'goods'" @close="close()" width="65%"
                            append-to-body :close-on-click-modal="false">
                            <el-table border v-loading="formLoading" :data="goodsList" ref="goodsList" v-tableHeight
                                :height="goodsList.length > 0 ? '900px' : '120px'">
                                <el-table-column label="商品名称" align="center" prop="goods_name" />
                                <el-table-column label="商品封面" align="center" prop="goods_cover">
                                    <template slot-scope="scope">
                                        <div v-if="scope.row.goods_cover" class="img-list">
                                            <el-image style="width: 40px; height: 40px;" :src="scope.row.goods_cover"
                                                :preview-src-list="[scope.row.goods_cover]">
                                            </el-image>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column label="商品规格" align="center" prop="goods_spec" >
                                    <template slot-scope="scope">
                                        <span>{{ scope.row.goods_spec.split(";;").toString().replace(/::/g,':') }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="发货数量" align="center" prop="send_number" />
                            </el-table>
                            <span slot="footer" class="dialog-footer">
                                <el-button @click="close()">确定</el-button>
                                <!-- <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button> -->
                            </span>
                        </el-dialog>
        <!-- <confirmPay v-if="handleShow == 'confirm'" :handleShow="handleShow" :orderNo="orderNo" @close="handleShow = ''"
            @load="getList" />
        <deliveySet v-if="handleShow == 'delivery'" :handleShow="handleShow" :orderNo="orderNo" @close="handleShow = ''"
            @load="getList" />
        <deliveyTrack v-if="handleShow == 'tracking'" :handleShow="handleShow" :orderNo="orderNo" @close="handleShow = ''"
            @load="getList" /> -->
        <!-- <el-dialog :title="title" visible v-if="handleShow == 'detail'" @close="close()" width="65%" append-to-body
            :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" v-loading="formLoading">

                <div style="margin-bottom: 30px;"><span class="tit">订单信息</span></div>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="总订单号:" prop="total_order_no">
                            <span class="p">{{ form.total_order_no }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="分订单号:" prop="order_no">
                            <span class="p">{{ form.order_no }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="订单状态:" prop="orders_state">
                            <span class="p">{{ selectDictLabel(btnList, form.orders_state) }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="支付订单号:" prop="out_trade_no">
                            <span class="p">{{ form.out_trade_no }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="订单总计:" prop="total_price">
                            <span class="p">{{ form.total_price }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="支付金额:" prop="pay_price">
                            <span class="p">{{ form.pay_price }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="下单时间:" prop="create_time">
                            <span class="p">{{ form.create_time }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="支付方式:" prop="pay_type">
                            <span class="p">{{ selectDictLabel(payType, form.pay_type) }}</span>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="订单取消时间:" prop="cancel_time">
                            <span class="p">{{ form.cancel_time }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="订单取消原因:" prop="cancel_reason">
                            <span class="p">{{ form.cancel_reason }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="优惠券金额:" prop="coupon_price">
                            <span class="p">{{ form.coupon_price }}</span>
                        </el-form-item>
                    </el-col>
                    
                    <el-col :span="12">
                        <el-form-item label="确认支付说明:" prop="confirm_pay_remark">
                            <span class="p">{{ form.confirm_pay_remark }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="支付凭证:" prop="confirm_pay_image">
                            <img :src="form.confirm_pay_image" class="avatar">
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-divider></el-divider>
                <div style="margin-bottom: 30px;"><span class="tit">用户信息</span></div>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="用户名:" prop="user.name">
                            <span class="p">{{ form.user.name }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="用户昵称:" prop="user.nicename">
                            <span class="p">{{ form.user.nicename }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="用户手机:" prop="user.mobile">
                            <span class="p">{{ form.user.mobile }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="用户头像:" prop="user.avatar">
                            <img :src="form.user.avatar" class="avatar">
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-divider></el-divider>
                <div style="margin-bottom: 30px;"><span class="tit">商品信息</span></div>
                <el-table :data = "form.items">
                    <el-table-column label="商品编号" align="center" prop="goods_code" />
                    <el-table-column label="商品封面" align="center" prop="goods_cover" >
                        <template slot-scope="scope">
                        <div v-if="scope.row.goods_cover" class="img-list">
                            <el-image style="width: 40px; height: 40px;border:1px solid #eee;border-radius: 50%;" :src="scope.row.goods_cover"
                                :preview-src-list="[scope.row.goods_cover]">
                            </el-image>
                        </div>
                    </template>
                    </el-table-column>
                    <el-table-column label="商品名称" align="center" prop="goods_name" />
                    <el-table-column label="商品规格" align="center" prop="goods_spec" >
                        <template slot-scope="scope">
                            <span>{{ scope.row.goods_spec.split(";;").toString().replace(/::/g,':') }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="销售价格" align="center" prop="price_selling" />
                    <el-table-column label="购买数量" align="center" prop="stock_sales" />
                    <el-table-column label="销售总价" align="center" prop="total_selling" />   
                </el-table>
                <el-divider></el-divider>
                <div style="margin-bottom: 30px;"><span class="tit">发货信息</span></div>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="发货姓名:" prop="truck.address_name">
                            <span class="p">{{ form.truck.address_name }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="发货手机:" prop="truck.address_mobile">
                            <span class="p">{{ form.truck.address_mobile }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="发货地址:" prop="truck.address_province" >
                            <span class="p">{{ form.truck.address_province }}{{ form.truck.address_city }}{{ form.truck.address_city }}{{ form.truck.address_area }}{{ form.truck.address_detailed }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="快递公司:" prop="truck.company_name">
                            <span class="p">{{ form.truck.company_name }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="快递单号:" prop="truck.send_number">
                            <span class="p">{{ form.truck.send_number }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="发货时间:" prop="truck.send_time">
                            <span class="p">{{ new Date(parseInt(form.truck.send_time) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ') }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="是否发货:" prop="truck.is_send">
                            {{ selectDictLabel(sendStatus, form.truck.is_send) }}
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="快递配送描述:" prop="truck.send_remark">
                            <span class="p">{{ form.truck.send_remark }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="close()">确定</el-button>
            </span>
        </el-dialog> -->
    </div>
</template>
<script>
import { getSendLists, cancelGoodsOrder, confirmTake } from "@/api/purchaseOrder/purchase"
// import confirmPay from "./handle/confirmPay"
// import deliveySet from "./handle/deliverySet"
// import deliveyTrack from "./handle/deliveryTrack"
import { departStatus, payType, payState } from "@/api/dictionary"

import throttle from 'lodash.throttle'
export default {
    name: 'order',
    components: {
        // confirmPay,
        // deliveySet,
        // deliveyTrack
    },
    props: {

    },
    data() {
        return {
            showSearch: true,
            loading: false,
            pageCount: 0,
            total: 0,
            queryParams: {
                page: 1,
                limit: 20,
                // key_order_no: null,
                // key_name: '',
            },
            tableList: [],
            statusList: departStatus,
            payType: payType,
            payState: payState,
            handleShow: "",
            orderNo: null,
            formLoading: false,
            form: {
                id: null,
                name: null,
            },
            rules: {
                name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }],
            },
            title: "",
            size: 'mini',
            curLine: 0,
            receiveStatus:[
            {
                    dictLabel: '未确认',
                    dictValue: 0
                },
                {
                    dictLabel: '已确认',
                    dictValue: 1
                },
            ],
            btnList: [
                {
                    dictLabel: '全部订单',
                    dictValue: ''
                },
                {
                    dictLabel: '待发货',
                    dictValue: 1
                },
                {
                    dictLabel: '待收货',
                    dictValue: 2
                },
                {
                    dictLabel: '已收货',
                    dictValue: 3
                },
            ],
            sendStatus:[
            {
                    dictLabel: '已发货',
                    dictValue: '1'
                },
                {
                    dictLabel: '未发货',
                    dictValue: 0
                },
            ],
            listCount:'',
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            this.loading = true;
            getSendLists(this.queryParams).then(res => {
                this.tableList = res.data.lists;
                this.pageCount = res.data.pageCount;
                this.listCount = res.data.listsCount;
                this.loading = false;
            });
        },
        handleGoods(row) {
            this.goodsList = row.items
            this.handleShow = "goods"
        },
        changeTab(item, index) {
            this.curLine = index
            this.queryParams.type = item.dictValue
            this.getList()
        },
        handleQuery() {
            this.queryParams.page = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        toggleSelection(row) {
            this.$refs.tableList.toggleRowSelection(row);
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selectData = selection;
        },
        handleBulk(ids) {
            this.$confirm('是否确认批量修改?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delSector({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("修改成功");
            })
        },
        /** 导出按钮操作 */
        handleExport() {
            const queryParams = this.queryParams;
            this.$confirm('是否确认导出所有数据项?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(function () {
                // return exportBanner(queryParams);
            }).then((response) => {
                // this.download(response.msg);
            });
        },
        close() {
            this.form = {}
            this.handleShow = ""
            this.getList()
        },
        // handleAble(row) {
        //     // let label = row.status == 0 ? '停用' : '启用';
        //     this.$confirm(`是否将“${row.name}”关闭?`, "警告", {
        //         confirmButtonText: "确定",
        //         cancelButtonText: "取消",
        //         type: "warning"
        //     }).then(function () {
        //         return setSectorStatus({ id: row.id });
        //     }).then(() => {
        //         this.getList();
        //         this.msgSuccess(`${label}成功`);
        //     })
        // },
        handleDelete(row) {
            this.$confirm('是否确认删除' + '"' + row.name + '"' + '?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return cancelGoodsOrder({ order_no: row.order_no });
            }).then(() => {
                this.getList();
                this.msgSuccess("删除成功");
            })
        },

        handleConfirm(row) {
            this.$confirm('是否确认收货?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return confirmTake({ send_id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("确认成功");
            })
            // this.handleShow = 'confirm'; ' + '"' + row.name + '"' + '
            // getHousingInfo({ code: row.code }).then(res => {
            //     this.title = "商品入库"
            //     this.stockRow = res.data;
            //     this.handleShow = 'audit';
            // })
        },

        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.formLoading = true;
                    setSector(this.form).then(res => {
                        this.msgSuccess("操作成功！");
                        this.close()
                        this.formLoading = false;
                        this.getList();
                    }).catch(() => {
                        this.formLoading = false;
                    })
                }
            })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
.decs {

    /deep/.el-descriptions--mini.is-bordered .el-descriptions-item__cell {
        padding: 0 10px;
    }

    /deep/.el-descriptions-item__cell {
        padding-left: 8px;
        font-size: 14px;
    }

    /deep/ .el-col {
        margin: 0px;
        padding: 0px;
        height: 30px;
        line-height: 30px;
    }

    /deep/.el-form-item__error {
        top: 21%;
        right: 5% !important;
        left: unset;
    }
}

.p {
    font-size: 14px;
}</style>
